#include "ball.h"

#include <QGraphicsSceneMouseEvent>
#include <QPainter>

#include "board.h"

Ball::Ball(Board *board, qint8 layer, qint32 scene_size, const pos_t &pos)
    : BoardItem(board, scene_size)
{
    setZValue(layer);
    setFlag(ItemIsMovable);
    set_game_position(pos);
}

void Ball::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
    QImage ball_img(":/images/ball");
    painter->drawImage(5, 5, ball_img.scaled(item_size() - 10, item_size() - 10));
}

void Ball::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    BoardItem::mouseReleaseEvent(event);
    if (event->button() == Qt::LeftButton) board()->drop_ball(this);
}

void Ball::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    BoardItem::mousePressEvent(event);
    if (event->button() == Qt::LeftButton) board()->drag_ball(this);
}
